<template>
<!--  vue2 在template 下面需要一个最外层的div 包裹-->
    <div class="login_container">
    <!--   要有个div 去包裹 图片和form表单   -->
      <div class="login_box">
        <!--        1.图片-->
        <div class="avatar_box">
          <!--动图gif-->
          <img src="../../assets/image/84f0de6bf43d7522c4a0e3d1aaffcf0a.gif">
        </div>
        <!--        2.form表单-->
        <el-form :model="loginForm" :rules="loginRules" ref="loginForm" class="login_form" >
          <h3>强智教育管理系统</h3>
        <!--          用户名-->
            <el-form-item prop="userName">
                <el-input type="text" v-model="loginForm.userName" placeholder="请输入用户名" prefix-icon="el-icon-user-solid" clearable></el-input>
            </el-form-item>
<!--          密码-->
          <el-form-item prop="password">
            <el-input type="password" v-model="loginForm.password" placeholder="请输入用户密码" prefix-icon="el-icon-lock" clearable></el-input>
          </el-form-item>

<!--          图片验证码区域-->
          <el-form-item prop="verifyCode">
            <div class="verifyCode_box">
              <el-input v-model="loginForm.verifyCode" placeholder="请输入图片验证码" class="verifyCode" prefix-icon="el-icon-mobile-phone" clearable></el-input>
              <img src="../../assets/image/20240325215000.png"  class="verifyCode_img">
            </div>
          </el-form-item>
        <!--          按钮-->
          <el-form-item class="login_btn">
            <el-button type="primary" @click="submitForm('loginForm')">确定</el-button>
            <el-button type="default" @click="resetForm('loginForm')">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
</template>

<script>
export default {
  name: 'Login',
  data(){
    return {
      loginForm :{
        userName:'',
        password:'',
        verifyCode:''
      },
      loginRules: {
        userName: [
          { required: true, message: '请输入用户名称', trigger: 'blur' },
          { min: 3, max: 16, message: '长度在 3 到 16 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入登录密码', trigger: 'blur' },
          { min: 3, max: 16, message: '长度在 3 到 16 个字符', trigger: 'blur' }
        ],
        verifyCode: [
          { required: true, message: '请输入验证码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm(formName){
      this.$refs[formName].validate((valid)=>{
        if(valid){
          this.$message.success("表单验证通过，跳转到后台")
        }else{
          this.$message.error("表单验证失败，请重新输入对应的值")
          return;
        }
      })
    },
    resetForm(formName){
      this.$refs[formName].resetFields()
    }
  }
}
</script>
<style lang="less" scoped>
  .login_container {
    height: 100%;
    background-color: aquamarine;
  }
  .login_box {
    width: 450px;
    height: 380px;
    background-color: #FFFFFF;
    border-radius: 10px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    .avatar_box{
      width: 120px;
      height: 120px;
      border-radius: 50%;
      border: 1px solid #EEEEEE;
      padding: 10px;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
      margin:-60px auto;
      background-color: #FFFFFF;
      img{
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: #EEEEEE;
      }
    }
    .login_form{
      position: absolute;
      bottom: 5px;
      width: 100%;
      padding: 0 20px;
      box-sizing: border-box; //ie盒子-
      //  图片验证码样式
      .verifyCode_box{
        display: flex;
        .verifyCode{
          width: 70%;
          justify-content: left;
        }
        .verifyCode_img{
          width: 30%;
          height: 45px;
          justify-content: flex-end;
          margin-top: -5px;
        }
      }
    }
    .login_btn{
      display: flex;
      justify-content: flex-end;
    }
  }
</style>
